package com.wzy.webuserdemo.intercept;

import com.wzy.webuserdemo.pojo.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user == null){
            request.setAttribute("msg","没有权限，请先登录");
            //response.sendRedirect("/login");
            request.getRequestDispatcher("/login").forward(request,response);
            return false;
        }
        return true;
    }
}
